package org.particles.gui;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;

public class NextStateAction extends AbstractSimAction {
	private static final long serialVersionUID = -3020745837202265834L;
	
	public NextStateAction() {
		super();
	}
	
	/**
	 * must be called after all properties (worldPanel, task, commonService) are set.
	 */
	public void initAction() {
		putValue(SHORT_DESCRIPTION, "Go to next state");
		putValue(MNEMONIC_KEY, KeyEvent.VK_S);
		putValue(SMALL_ICON, new ImageIcon(getCommonService().findImageUrlByName("StepForward16")));
		putValue(LARGE_ICON_KEY, new ImageIcon(getCommonService().findImageUrlByName("StepForward24")));
		putValue(NAME, "Next state");
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		final boolean oldValue = getWorldTimeTask().isRunning();
		final boolean newValue = false;
		getWorldTimeTask().setRunning(newValue);
		if(oldValue != newValue) {
			firePropertyChange(GuiUtil.PROP_TASKRUN, oldValue, newValue);
		}
		getWorldPanel().getWorld().nextState();
		getWorldPanel().repaint();
	}

}
